$(function () {




    $('#shijianyi').datetimepicker({
        //viewMode: 'day',
        format: 'YYYY-MM-DD'
    });
    $('#shijianer').datetimepicker({
        format: 'YYYY-MM-DD',
        useCurrent: false //Important! See issue #1075
    });
    $("#shijianyi").on("dp.change", function (e) {
        $('#shijianer').data("DateTimePicker").minDate(e.date);
    });
    $("#shijianer").on("dp.change", function (e) {
        $('#shijianyi').data("DateTimePicker").maxDate(e.date);
    });


    $('#date').datetimepicker({
        format: 'YYYY-MM-DD',
        useCurrent: false //Important! See issue #1075
    });

    $('#Sdate').datetimepicker({
        format: 'YYYY-MM-DD',
        useCurrent: false //Important! See issue #1075
    });



    $('#table').bootstrapTable({
        url: '${pageContext.request.contextPath}/../../house/list',
        columns: [
            {
                field: 'id',
                title: 'id',
                visible : false,
            },{
                field: 'doornumber',
                title: '房屋门牌号'
            }, {
                field: 'typeb.id',
                title: '房屋状态',
                formatter: function (value, row, index) {
                    if (row.typeb.id == 1) {
                        return "空闲";
                    }else {
                        return "已售";
                    }
                }

            },{
                field: 'userdetails.name',
                title: '姓名',
                // visible : false,
            },
            {
                field: 'userdetails.phone',
                title: '手机号',
                // visible : false,
            },{
                field: 'userdetails.sfz',
                title: '身份证号码',
                // visible : false,
            },{
                field: 'userdetails.property.name',
                title: '产权',
                // visible : false,
            },
            {
                field: 'sale.name',
                title: '楼'
            }, {
                field: 'danyuan.name',
                title: '单元'
            }, {
                field: 'floor',
                title: '层数'
            }, {
                field: 'huxing.name',
                title: '户型'
            }, {
                field: 'direction.name',
                title: '房屋朝向'
            }, {
                field: 'measure',
                title: '平米',
                formatter: function (value, row, index) {
                    var jia = row .measure+"平方米";
                    return jia;
                }
            },{
                field:'remark',
                title:'简介'
            }],
        contentType:"application/x-www-form-urlencoded",
        queryParamsType: '',
        height: 700,
        pageNumber: 1,
        pageSize: 15,
        pagination:true,
        queryParams: queryParams,
        sidePagination:'server',
        onDblClickRow: function (row, $element, field) {
            $("#myModal3").modal("hide")
            $("#Smenpai").val(row.doornumber)
            $("#Sname").val(row.userdetails.name)
            $("#Sphone").val(row.userdetails.phone)
        },
    });
















    $('#Sssjj').datetimepicker({
        //viewMode: 'day',
        format: 'YYYY-MM-DD HH:mm:ss',

    });


    $('#Stable').bootstrapTable({
        url: '${pageContext.request.contextPath}/../../warranty/chaxunquanbu',
        columns: [{
            field: 'id',
            title: 'id',
            visible : false,

        },{
            field: 'doornumber',
            title: '门牌号'
        },{
            field: 'name',
            title: '姓名'
        },{
            field:'phone',
            title:'手机号'
        },{
            field: 'order',
            title: '保修编号'
        },{
            field:'date',
            title:'保修日期'
        },{
            field : 'wmoney',
            title : '物资费用'
        },{
            field: 'rmoney',
            title: '服务费用'
        },{
            field: 'type',
            title: '维修状态',
            formatter:function (value,row,index) {
                if (row.type==1){
                    return "已维修";
                }else if(row.type==2) {
                    return "未维修";

                }
            }
        },{
            field: 'wname',
            title: '维修员工'
        },{
            field: 'neirong',
            title: '保修内容'
        },{
            field: 'text',
            title: '备注'
        },{
            field : 'xx',
            title : '操作',


            formatter:function(value,row,index){

                return "<a href='javascript:del("+row.id+")'>删除</a>" ;
            }
        }],
        contentType : "application/x-www-form-urlencoded",
        queryParamsType:'',
        height:680,
        pageList:[5,10,15],
        pageNumber:1,
        pageSize:15,
        pagination:true,
        sidePagination:'server',

        onDblClickRow: function (row, $element, field) {
            $("#myModal2").modal("show");
            $("#menpai").val(row.doornumber);
            $("#name").val(row.name);
            $("#phone").val(row.phone)
            $("#order").val(row.order)
            $("#date").val(row.date)
            $("#type").val(row.type)
            $("#wname").val(row.wname)
            $("#wmoney").val(row.wmoney)
            $("#neirong").val(row.neirong)
            $("#text").val(row.text)
            $("#yin1").val(row.id)

            $("#rmoney").val(row.rmoney)
        },
    });
})

//修改数据
function upd() {
    var opt = $("#table").bootstrapTable('getOptions');
    var Sdoornumber = $("#menpai").val();
    var name = $("#name").val();
    var phone=$("#phone").val();
    var order = $("#order").val();
    var date=$("#date").val();
    var type=$("#SStype").val();
    var wname=$("#wname").val();
    var neirong=$("#neirong").val();
    var text=$("#text").val();
    var rmoney=$("#rmoney").val();

    var wmoney=$("#wmoney").val();


    var yin1 = $("#yin1").val();
    $.post("${pageContext.request.contextPath}/../../warranty/Qxiugai",{"id":yin1,"doornumber":Sdoornumber,"name":name,"date":date,"phone":phone,"order":order,"type":type,"wname":wname,"neirong":neirong,"text":text,"rmoney":rmoney,"wmoney":wmoney,"pageNumber":opt.pageNumber,"pageSize":opt.pageSize},function (data) {
        $("#Stable").bootstrapTable("load",data);
    })
}


function add2() {
    var opt = $("#table").bootstrapTable('getOptions');
    var Sdoornumber = $("#Smenpai").val();
    var name = $("#Sname").val();
    var phone=$("#Sphone").val();
    var order = $("#Sorder").val();
    var date=$("#Sdate").val();
    var type=$("#Stype").val();
    var wname=$("#Swname").val();
    var neirong=$("#Sneirong").val();
    var text=$("#Stext").val();
    var rmoney=$("#Srmoney").val();
    var wmoney=$("#Swmoney").val();
    $.post("${pageContext.request.contextPath}/../../warranty/Qtianjia",{"doornumber":Sdoornumber,"name":name,"date":date,"phone":phone,"order":order,"type":type,"wname":wname,"neirong":neirong,"text":text,"rmoney":rmoney,"wmoney":wmoney,"pageNumber":opt.pageNumber,"pageSize":opt.pageSize},function (data) {
        $("#Stable").bootstrapTable("load",data);
    })
}


//删除
function del(id) {
    var id=id;
    var opt = $("#table").bootstrapTable('getOptions');

    $.post("${pageContext.request.contextPath}/../../warranty/Qdel",{"id":id,"pageNumber":opt.pageNumber,"pageSize":15},function (data) {
        $("#Stable").bootstrapTable("load",data);
    })
}

//按条件查询
function ban(){
    var opt = $("#table").bootstrapTable('getOptions') ;
    var firstDate = $("#shijianer").val() ;
    var secondDate = $("#shijianyi").val() ;
    var type=$("#SStype").val();
    $.post('${pageContext.request.contextPath}/../../warranty/chaxunquanbu',{'pageNumber':opt.pageNumber,'pageSize':opt.pageSize,'firstDate':firstDate,'secondDate':secondDate,'type':type},function(data){
        //重新给table绑定数据5
        $("#Stable").bootstrapTable("load",data) ;
    }) ;

};

function queryParams(params) {
    var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
        'pageSize': params.pageSize,  //页面大小
        'pageNumber': params.pageNumber, //页码
        'secondDate':$("#shijianyi").val(),
        'firstDate':$("#shijianer").val(),
        'type': $("#SStype").val(),
    };
    return temp;
};








//打开模态框
function san() {
    $("#myModal3").modal("show");
}


//table查询
function search() {
    var opt = $("#table").bootstrapTable('getOptions');

    var shu ;
    var node = $('#tt').tree('getSelected');
    if (node){
        var s = node.text;
        if (node.attributes){
            s += ","+node.attributes.p1+","+node.attributes.p2;
        }
        shu = s;
    }
    var men=$("#men").val();
    $.post('${pageContext.request.contextPath}/../../house/list', {
        'shu':shu,
        'number':men,
        'type':2,
        'pageSize': opt.pageSize,
        'pageNumber': 1
    }, function (data) {

        //重新给table绑定数据
        $("#table").bootstrapTable("load", data);
    });
}

//table查询
function queryParams(params) {
    var shu ;
    var node = $('#tt').tree('getSelected');
    if (node){
        var s = node.text;
        if (node.attributes){
            s += ","+node.attributes.p1+","+node.attributes.p2;
        }
        shu = s;
    }
    var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
        'pageSize': params.pageSize,  //页面大小
        'pageNumber': params.pageNumber, //页码
        'shu':shu,
        'number':$("#men").val(),
        'type':2,
    };
    return temp;
};






